package com.leetCode;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-10-04 02:47:29
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-10-04     张李鑫                     1.0         1.0 Version
 */
public class CharIsValid {

    public static boolean isValid(String s) {
        int p1 = 0;
        int p2 = 0;
        int p3 = 0;
        char[] chars = s.toCharArray();
        for (char aChar : chars) {
            if (aChar == '(') {
                p1++;
            } else if (aChar == ')') {
                p1--;
            } else if (aChar == '[') {
                p2++;
            } else if (aChar == ']') {
                p2--;
            } else if (aChar == '{') {
                p3++;
            } else if (aChar == '}') {
                p3--;
            }
        }
        return p1 == p2 && p2 == p3 && p1 == 0;
    }

    public static char getChar(char s) {
        switch (s) {
            case '(':
                return ')';
            case '{':
                return '}';
            case '[':
                return ']';
            default:
                break;
        }
        return ' ';
    }

    public static void main(String[] args) {
        boolean valid = isValid("()");
        System.out.println(valid);
    }
}
